package com.gosophia.conference.action.notification;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.gosophia.commons.web.action.BaseSupportAction;
import com.gosophia.conferenceManagement.notification.dto.NotificationJobDataDTO;
import com.gosophia.conferenceManagement.notification.dto.SendNotificationJobDataDTO;
import com.gosophia.conferenceManagement.notification.ws.NotificationWebService;
import com.gosophia.conferenceManagement.notification.ws.SendNotificationWebService;
import com.gosophia.taskManagement.dto.JobDTO;
import com.gosophia.taskManagement.ws.TaskManagementWebService;
import com.gosophia.userManagement.dto.UserInfoDTO;
import com.gosophia.userManagement.ws.UserManagementWebService;

/**
 * 查询通知会议审批详细信息Action
 * @author gaoweiguang
 * @since  2011-3-26
 *  Copyright (c) 2010 Gosophia corporation All Rights Reserved
 */
@Scope("prototype")
@Controller("GetNotificationProcessDetailAction")
public class GetNotificationProcessDetailAction extends BaseSupportAction {

	private static final long serialVersionUID = -5783949380747143058L;

	@Autowired
	private NotificationWebService notificationWebService;

	@Autowired
	private SendNotificationWebService sendNotificationWebService;

    @Autowired
    private TaskManagementWebService taskManagementWebService;

	@Autowired
	private UserManagementWebService userManagementWebService;

	private NotificationJobDataDTO notificationJobDataDTO;

    private SendNotificationJobDataDTO sendNotificationJobDataDTO;

	private String onlineIsEdit = "0,0";

	private String onlinePath;

	private String onlineVersion;

	private Long jobId;

	private String pageType;
	
    private JobDTO sendJobDto;
    
    private List<UserInfoDTO> sendUsers = new ArrayList<UserInfoDTO>();

	@Override
	public String _execute() throws Exception {
		notificationJobDataDTO = notificationWebService
				.findNotificationJobDataByJobId(jobId);
		sendJobDto = taskManagementWebService.findJobDetailByJobId(jobId);
		if(notificationJobDataDTO==null) {
			notificationJobDataDTO = notificationWebService
			.findNotificationJobDataByJobId(sendJobDto.getPreviousJobDTO().getJobId());
			onlinePath = notificationJobDataDTO.getOnlineDocumentDTO()
			.getDocumentPath();
	         onlineVersion = notificationJobDataDTO.getOnlineDocumentDTO()
			.getDocumentVersion();	
		} else {
			onlinePath = notificationJobDataDTO.getOnlineDocumentDTO()
			.getDocumentPath();
	         onlineVersion = notificationJobDataDTO.getOnlineDocumentDTO()
			.getDocumentVersion();	
		}
		
		if ("finishedTypeApprovalDetail".equals(pageType)) {// 处理页面审批历史记录传的参数
			pageType = "approvalDetail";
		} else if ("预通知审批".equals(notificationJobDataDTO.getJobDTO()
				.getJobType())
				|| "正式通知审批".equals(notificationJobDataDTO.getJobDTO()
						.getJobType())) {
			pageType = "approvalDetail";
		} else if ("预通知发送".equals(sendJobDto.getJobType()) || 
				"正式通知发送".equals(sendJobDto.getJobType())) {
			sendNotificationJobDataDTO = sendNotificationWebService.findSendNotificationJobDataByJobIdAndSendUserId(jobId);
			if(sendNotificationJobDataDTO.getReceiveUserId()!=null 
					&& sendNotificationJobDataDTO.getReceiveUserId().size()!=0) {
				List<UserInfoDTO> AllUser = userManagementWebService.findAllUserInfo();
				for(Long sendUserId:sendNotificationJobDataDTO.getReceiveUserId()) {
                     for(UserInfoDTO user:AllUser) {
                    	 if(sendUserId.equals(user.getUserInfoId())) {
                    		 sendUsers.add(user);
                    	 }
                     }
				}
			}
			return "sendMailDetail";
		} else  {
			pageType = "otherDetail";
		}
		
		return SUCCESS;
	}

	public NotificationJobDataDTO getNotificationJobDataDTO() {
		return notificationJobDataDTO;
	}

	public void setNotificationJobDataDTO(
			NotificationJobDataDTO notificationJobDataDTO) {
		this.notificationJobDataDTO = notificationJobDataDTO;
	}

	public Long getJobId() {
		return jobId;
	}

	public void setJobId(Long jobId) {
		this.jobId = jobId;
	}

	public String getOnlineIsEdit() {
		return onlineIsEdit;
	}

	public void setOnlineIsEdit(String onlineIsEdit) {
		this.onlineIsEdit = onlineIsEdit;
	}

	public String getOnlinePath() {
		return onlinePath;
	}

	public void setOnlinePath(String onlinePath) {
		this.onlinePath = onlinePath;
	}

	public String getOnlineVersion() {
		return onlineVersion;
	}

	public void setOnlineVersion(String onlineVersion) {
		this.onlineVersion = onlineVersion;
	}

	public void setPageType(String pageType) {
		this.pageType = pageType;
	}

	public String getPageType() {
		return pageType;
	}

	public SendNotificationJobDataDTO getSendNotificationJobDataDTO() {
		return sendNotificationJobDataDTO;
	}

	public void setSendNotificationJobDataDTO(
			SendNotificationJobDataDTO sendNotificationJobDataDTO) {
		this.sendNotificationJobDataDTO = sendNotificationJobDataDTO;
	}

	public JobDTO getSendJobDto() {
		return sendJobDto;
	}

	public void setSendJobDto(JobDTO sendJobDto) {
		this.sendJobDto = sendJobDto;
	}

	public List<UserInfoDTO> getSendUsers() {
		return sendUsers;
	}

	public void setSendUsers(List<UserInfoDTO> sendUsers) {
		this.sendUsers = sendUsers;
	}

    	
}
